package com.itheima.area.controller;

import com.itheima.area.pojo.CustFarmlandCrop;
import com.itheima.area.service.CropService;
import com.itheima.entity.Result;
import com.itheima.entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @PackageName com.itheima.area.controller
 * @ProjectName Ceres-Work
 * @Created by Chanly on 2020/10/15 20:01
 **/
@RequestMapping("/crop")
@RestController
public class CropController {
    @Autowired
    private CropService cropService;
    @GetMapping
    public Result findAll(){
        try {
            List<CustFarmlandCrop> cropList = cropService.findAll();
            return new Result(true, StatusCode.OK,"查询所有成功",cropList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,StatusCode.ERROR,"查询所有失败");
        }
    }
   @PutMapping("/add")
    public Result add(@RequestBody CustFarmlandCrop custFarmlandCrop){
       try {
           cropService.add(custFarmlandCrop);
           return new Result(true,StatusCode.OK,"修改成功");
       } catch (Exception e) {
           e.printStackTrace();
           return new Result(false,StatusCode.ERROR,"修改农作物失败");
       }
   }
}
